blufin 0.1.0
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.
- checksums.yaml +7 -0
- data/bin/bf +5 -0
- data/bin/blufin +5 -0
- data/lib/blufin.rb +245 -0
- data/lib/core/code_scanners/common/scanner_common.rb +83 -0
- data/lib/core/code_scanners/common/scanner_java.rb +106 -0
- data/lib/core/code_scanners/scanner_java_embedded_objects.rb +386 -0
- data/lib/core/code_scanners/scanner_java_enums.rb +125 -0
- data/lib/core/code_scanners/scanner_java_source.rb +29 -0
- data/lib/core/code_scanners/scanner_java_tests.rb +157 -0
- data/lib/core/error_handling/schema_error.rb +9 -0
- data/lib/core/error_handling/sql_error.rb +21 -0
- data/lib/core/error_handling/sql_error_handler.rb +149 -0
- data/lib/core/error_handling/yml_error.rb +21 -0
- data/lib/core/error_handling/yml_error_handler.rb +437 -0
- data/lib/core/mysql.rb +347 -0
- data/lib/core/opt.rb +21 -0
- data/lib/core/site/site.rb +26 -0
- data/lib/core/site/site_auth.rb +88 -0
- data/lib/core/site/site_embedded.rb +27 -0
- data/lib/core/site/site_ports.rb +9 -0
- data/lib/core/site/site_resolver.rb +276 -0
- data/lib/core/site/site_services.rb +162 -0
- data/lib/core/site/site_ui.rb +16 -0
- data/lib/core/yml/config/yml_config_validator.rb +219 -0
- data/lib/core/yml/maven/yml_maven_validator.rb +1132 -0
- data/lib/core/yml/resource/yml_resource_validator.rb +154 -0
- data/lib/core/yml/schema/yml_schema_flags.rb +9 -0
- data/lib/core/yml/schema/yml_schema_validator.rb +1850 -0
- data/lib/core/yml/yml_cache_handler.rb +115 -0
- data/lib/core/yml/yml_common.rb +487 -0
- data/lib/core/yml/yml_meta_writer_base.rb +300 -0
- data/lib/core/yml/yml_outputter.rb +307 -0
- data/lib/core/yml/yml_validator_base.rb +630 -0
- data/lib/core/yml_writers/yml_configuration_writer.rb +40 -0
- data/lib/core/yml_writers/yml_java_api_resource_writer.rb +348 -0
- data/lib/core/yml_writers/yml_java_cron_type_writer.rb +113 -0
- data/lib/core/yml_writers/yml_java_css_dependency_writer.rb +59 -0
- data/lib/core/yml_writers/yml_java_dao_writer.rb +364 -0
- data/lib/core/yml_writers/yml_java_dto_writer.rb +251 -0
- data/lib/core/yml_writers/yml_java_embedded_object_writer.rb +968 -0
- data/lib/core/yml_writers/yml_java_enum_writer.rb +161 -0
- data/lib/core/yml_writers/yml_java_js_dependency_writer.rb +59 -0
- data/lib/core/yml_writers/yml_java_message_type_writer.rb +106 -0
- data/lib/core/yml_writers/yml_java_meta_writer.rb +173 -0
- data/lib/core/yml_writers/yml_java_model_writer.rb +510 -0
- data/lib/core/yml_writers/yml_java_pom_writer.rb +1050 -0
- data/lib/core/yml_writers/yml_java_resource_data_writer.rb +251 -0
- data/lib/core/yml_writers/yml_java_sdk_writer.rb +732 -0
- data/lib/core/yml_writers/yml_java_validator_writer.rb +280 -0
- data/lib/core/yml_writers/yml_java_worker_writer.rb +81 -0
- data/lib/core/yml_writers/yml_sql_structure_writer.rb +307 -0
- data/lib/core/yml_writers/yml_sql_template_writer.rb +243 -0
- data/lib/core/yml_writers/yml_vue_service_writer.rb +170 -0
- data/lib/core/yml_writers/yml_writer_base.rb +114 -0
- data/lib/routes/api_list.rb +35 -0
- data/lib/routes/api_meta.rb +59 -0
- data/lib/routes/build.rb +46 -0
- data/lib/routes/create/create_api.rb +35 -0
- data/lib/routes/create/create_ui.rb +84 -0
- data/lib/routes/export.rb +56 -0
- data/lib/routes/generate/generate_api.rb +225 -0
- data/lib/routes/generate/generate_img_favicon.rb +56 -0
- data/lib/routes/generate/generate_img_landing.rb +94 -0
- data/lib/routes/generate/generate_lambda.rb +43 -0
- data/lib/routes/lint.rb +35 -0
- data/lib/routes/mysql_reset.rb +43 -0
- data/lib/routes/release_blufin.rb +351 -0
- data/lib/routes/run.rb +35 -0
- data/lib/version.rb +1 -0
- data/opt/README.MD +2 -0
- data/opt/config/schema.yml +73 -0
- data/opt/config/template.yml +25 -0
- data/opt/sql/data/config/data-client.sql +7 -0
- data/opt/sql/data/config/data-db-configuration-property.sql +47 -0
- data/opt/sql/data/config/data-db-configuration.sql +9 -0
- data/opt/sql/data/config/data-db.sql +175 -0
- data/opt/sql/data/config/data-profile-api.sql +47 -0
- data/opt/sql/data/config/data-profile-cron.sql +0 -0
- data/opt/sql/data/config/data-profile-worker.sql +0 -0
- data/opt/sql/data/config/data-profile.sql +87 -0
- data/opt/sql/data/config/data-project.sql +95 -0
- data/opt/sql/structure/blufin-master-structure-fks.sql +65 -0
- data/opt/sql/structure/blufin-master-structure.sql +97 -0
- data/opt/sql/structure/blufin-mock-structure-fks.sql +38 -0
- data/opt/sql/structure/blufin-mock-structure.sql +98 -0
- data/opt/sql/templates/config/template-client.sql +7 -0
- data/opt/sql/templates/config/template-db-configuration-property.sql +11 -0
- data/opt/sql/templates/config/template-db-configuration.sql +9 -0
- data/opt/sql/templates/config/template-db.sql +21 -0
- data/opt/sql/templates/config/template-profile-api.sql +11 -0
- data/opt/sql/templates/config/template-profile-cron.sql +7 -0
- data/opt/sql/templates/config/template-profile-worker.sql +7 -0
- data/opt/sql/templates/config/template-profile.sql +21 -0
- data/opt/sql/templates/config/template-project.sql +23 -0
- data/opt/yml/api/schema/config/client.yml +14 -0
- data/opt/yml/api/schema/config/db.yml +45 -0
- data/opt/yml/api/schema/config/db_configuration.yml +22 -0
- data/opt/yml/api/schema/config/db_configuration_property.yml +22 -0
- data/opt/yml/api/schema/config/profile.yml +53 -0
- data/opt/yml/api/schema/config/profile_api.yml +22 -0
- data/opt/yml/api/schema/config/profile_cron.yml +14 -0
- data/opt/yml/api/schema/config/profile_worker.yml +14 -0
- data/opt/yml/api/schema/config/project.yml +48 -0
- data/opt/yml/api/schema/mock/mock.yml +99 -0
- data/opt/yml/api/schema/mock/mock_nested_if_enum.yml +16 -0
- data/opt/yml/api/schema/mock/mock_nested_if_enum_system.yml +16 -0
- data/opt/yml/api/schema/mock/mock_nested_linked.yml +43 -0
- data/opt/yml/api/schema/mock/mock_nested_multiple.yml +61 -0
- data/opt/yml/api/schema/mock/mock_nested_single.yml +67 -0
- data/opt/yml/api/schema/mock/mock_nested_single_super_deep.yml +32 -0
- data/opt/yml/api/schema/mock/mock_nested_single_super_super_deep.yml +17 -0
- metadata +240 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: bfeeca4906f67d952ae139a35756520b322bc3ad
|
|
4
|
+
data.tar.gz: 88570df1555e0878c833f036eb7eaba0c3ef72ab
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '048dae1911dda7be0142c69b85b8bbbecc71e5e854c083b9b20858f08535a9c5db073d4d2097817647c7ea2571f9db23ffcf2827a8069aea0a7236d0435aec1f'
|
|
7
|
+
data.tar.gz: 90ec701ffad0f5ef265d68663420e5231bf65aff0bb50dff31f8feb16a1ce0f135fdd04f95416a0e019e14e768dc2220a3fd1223063b2a6e8e44ba3456ce8c06
|
data/bin/bf
ADDED
data/bin/blufin
ADDED
data/lib/blufin.rb
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
require 'blufin-lib'
|
|
2
|
+
require 'columnist'
|
|
3
|
+
require 'convoy'
|
|
4
|
+
require 'mysql2'
|
|
5
|
+
require 'yaml'
|
|
6
|
+
|
|
7
|
+
require_relative 'version'
|
|
8
|
+
require 'core/site/site_services'
|
|
9
|
+
require 'core/yml/yml_validator_base'
|
|
10
|
+
require 'core/yml_writers/yml_writer_base'
|
|
11
|
+
|
|
12
|
+
Dir["#{File.dirname(__FILE__)}/core/**/*.rb"].each { |file| load(file) unless file =~ /\/(site_services|yml_validator_base|yml_writer_base)\.rb\z/ }
|
|
13
|
+
Dir["#{File.dirname(__FILE__)}/routes/**/*.rb"].each { |file| load(file) }
|
|
14
|
+
|
|
15
|
+
module App
|
|
16
|
+
|
|
17
|
+
GEM_NAME = 'blufin'
|
|
18
|
+
SCHEMA_FILE = "#{App::Opt::get_base_path}#{App::Opt::OPT_PATH}/config/schema.yml"
|
|
19
|
+
TEMPLATE_FILE = "#{App::Opt::get_base_path}#{App::Opt::OPT_PATH}/config/template.yml"
|
|
20
|
+
CONFIG_FILE = '~/.blufin.yml'
|
|
21
|
+
|
|
22
|
+
def self.execute
|
|
23
|
+
|
|
24
|
+
begin
|
|
25
|
+
|
|
26
|
+
unless ARGV[0] == 'setup' || ARGV[0] == 'x'
|
|
27
|
+
Blufin::Config::init(SCHEMA_FILE, TEMPLATE_FILE, App::CONFIG_FILE, App::GEM_NAME)
|
|
28
|
+
Blufin::Projects::init(Blufin::Config::get, App::CONFIG_FILE)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
Convoy::App.create do |app|
|
|
32
|
+
|
|
33
|
+
# http://patorjk.com/software/taag/#p=display&f=ANSI%20Shadow&t=Blufin
|
|
34
|
+
app.version BLUFIN_VERSION
|
|
35
|
+
app.summary <<TEMPLATE
|
|
36
|
+
\x1B[48;5;20m\x1B[38;5;255m Blufin \x1B[0m\x1B[0m \x1B[38;5;32m\xe2\x80\x94 Command-Line Interface \xe2\x80\x94\x1B[38;5;248m 🐳
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
██████╗ ██╗ ██╗ ██╗███████╗██╗███╗ ██╗
|
|
40
|
+
██╔══██╗██║ ██║ ██║██╔════╝██║████╗ ██║
|
|
41
|
+
██████╔╝██║ ██║ ██║█████╗ ██║██╔██╗ ██║
|
|
42
|
+
██╔══██╗██║ ██║ ██║██╔══╝ ██║██║╚██╗██║
|
|
43
|
+
██████╔╝███████╗╚██████╔╝██║ ██║██║ ╚████║
|
|
44
|
+
╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝\x1B[0m
|
|
45
|
+
TEMPLATE
|
|
46
|
+
app.description "The secret sauce that makes everything 'tick'..."
|
|
47
|
+
|
|
48
|
+
# b - BUILD
|
|
49
|
+
app.command :build, :aliases => [:b] do |build|
|
|
50
|
+
build.summary "Build #{Blufin::Terminal::format_highlight('project-specific')} java services #{Blufin::Terminal::format_invalid('@deprecated')}"
|
|
51
|
+
build.options do |opts|
|
|
52
|
+
opts.opt :skip_tests, 'Skip tests', :short => '-S', :long => '--skip', :type => :boolean
|
|
53
|
+
end
|
|
54
|
+
build.action do |opts, args|
|
|
55
|
+
AppCommand::Build.new(opts, args).execute
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# c - CREATE
|
|
60
|
+
app.command :create, :aliases => [:c] do |create|
|
|
61
|
+
create.summary 'Create skeleton project from archetype(s)'
|
|
62
|
+
# a - CREATE API
|
|
63
|
+
create.command :api, :aliases => [:a] do |create_api|
|
|
64
|
+
create_api.summary 'Create API skeleton'
|
|
65
|
+
create_api.action do |opts, args|
|
|
66
|
+
AppCommand::CreateApi.new(opts, args).execute
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
# u - CREATE UI
|
|
70
|
+
create.command :ui, :aliases => [:u] do |create_ui|
|
|
71
|
+
create_ui.summary 'Create UI skeleton'
|
|
72
|
+
create_ui.action do |opts, args|
|
|
73
|
+
AppCommand::CreateUI.new(opts, args).execute
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
# CREATE (Default)
|
|
77
|
+
create.action do
|
|
78
|
+
system("#{App::GEM_NAME} c -h")
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# e - EXPORT
|
|
83
|
+
app.command :export, :aliases => [:e] do |export|
|
|
84
|
+
export.summary 'Export internal data structures'
|
|
85
|
+
export.options do |opts|
|
|
86
|
+
opts.opt :maven_blufin, 'Maven BOM (Blufin)', :short => '-m', :long => '--maven-blufin', :type => :boolean
|
|
87
|
+
opts.opt :maven_app, 'Maven BOM (App)', :short => '-M', :long => '--maven-app', :type => :boolean
|
|
88
|
+
end
|
|
89
|
+
export.action do |opts, args|
|
|
90
|
+
AppCommand::Export.new(opts, args).execute
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# g - GENERATE
|
|
95
|
+
app.command :generate, :aliases => [:g] do |generate|
|
|
96
|
+
generate.summary "Generate #{Blufin::Terminal::format_highlight('code')} (and other things)"
|
|
97
|
+
# a - GENERATE API
|
|
98
|
+
generate.command :api, :aliases => [:a] do |generate_api|
|
|
99
|
+
generate_api.summary 'Generate boiler-plate API code (from YML files)'
|
|
100
|
+
generate_api.action do |opts, args|
|
|
101
|
+
AppCommand::GenerateApi.new(opts, args).execute
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
# l - GENERATE LAMBDA
|
|
105
|
+
generate.command :lambda, :aliases => [:l] do |generate_lambda|
|
|
106
|
+
generate_lambda.summary 'Generate boiler-plate AWS Lambda code'
|
|
107
|
+
generate_lambda.action do |opts, args|
|
|
108
|
+
AppCommand::GenerateLambda.new(opts, args).execute
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
# generate - GENERATE UI
|
|
112
|
+
generate.command :ui, :aliases => [:u] do |generate_ui|
|
|
113
|
+
generate_ui.summary 'Generate UI stuff'
|
|
114
|
+
# a - GENERATE UI LANDING PAGE
|
|
115
|
+
generate_ui.command :img_landing, :aliases => [:l] do |generate_ui_img_landing|
|
|
116
|
+
generate_ui_img_landing.summary 'Generate different landing page image sizes'
|
|
117
|
+
generate_ui_img_landing.options do |opts|
|
|
118
|
+
opts.opt :add_size, 'Add image size (in top-left corner)', :short => '-s', :long => '--add-size', :type => :boolean
|
|
119
|
+
opts.opt :quality, 'Quality of the image (default: 60)', :short => '-q', :long => '--quality', :type => :string, :default => '60'
|
|
120
|
+
opts.opt :skip_confirm, 'Skip confirmation', :short => '-y', :long => '--skip-confirm', :type => :boolean
|
|
121
|
+
end
|
|
122
|
+
generate_ui_img_landing.action do |opts, args|
|
|
123
|
+
AppCommand::GenerateUIImageLanding.new(opts, args).execute
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
# a - GENERATE UI FAVICON
|
|
127
|
+
generate_ui.command :img_favicon, :aliases => [:f] do |generate_ui_img_favicon|
|
|
128
|
+
generate_ui_img_favicon.summary 'Generate favicon.ico file'
|
|
129
|
+
generate_ui_img_favicon.action do |opts, args|
|
|
130
|
+
AppCommand::GenerateUIFavIcon.new(opts, args).execute
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
# GENERATE UI (Default)
|
|
134
|
+
generate_ui.action do
|
|
135
|
+
system("#{App::GEM_NAME} g ui -h")
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
# GENERATE (Default)
|
|
139
|
+
generate.action do
|
|
140
|
+
system("#{App::GEM_NAME} g -h")
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# l - LINT
|
|
145
|
+
app.command :lint, :aliases => [:l] do |lint|
|
|
146
|
+
lint.summary "Scans code for errors/anti-patterns #{Blufin::Terminal::format_invalid('@todo')}"
|
|
147
|
+
lint.action do |opts, args|
|
|
148
|
+
AppCommand::Lint.new(opts, args).execute
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# M - MYSQL
|
|
153
|
+
app.command :mysql, :aliases => [:M] do |mysql|
|
|
154
|
+
mysql.summary 'Manage development databases (and mock data)'
|
|
155
|
+
# r - MYSQL RESET
|
|
156
|
+
mysql.command :reset, :aliases => [:r] do |mysql_reset|
|
|
157
|
+
mysql_reset.summary 'Reset development databases to a standard configuration'
|
|
158
|
+
mysql_reset.options do |opts|
|
|
159
|
+
opts.opt :skip_confirm, 'Skip confirmation (a safety measure to prevent accidental reset)', :short => '-y', :long => '--skip-confirm', :type => :boolean
|
|
160
|
+
opts.opt :verbose, 'Verbose', :short => '-v', :long => '--verbose', :type => :boolean
|
|
161
|
+
end
|
|
162
|
+
mysql_reset.action do |opts, args|
|
|
163
|
+
AppCommand::MySQLReset.new(opts, args).execute
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
# MYSQL (Default)
|
|
167
|
+
mysql.action do
|
|
168
|
+
system("#{App::GEM_NAME} M -h")
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# r - RUN
|
|
173
|
+
app.command :run, :aliases => [:r] do |run|
|
|
174
|
+
run.summary "Run a project/service #{Blufin::Terminal::format_invalid('@todo')}"
|
|
175
|
+
run.action do |opts, args|
|
|
176
|
+
AppCommand::Run.new(opts, args).execute
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# R - RELEASE
|
|
181
|
+
# TODO - This might need to be behind some-kind of toggle so devs can't just release blufin, willy-nilly.
|
|
182
|
+
app.command :release, :aliases => [:R] do |release|
|
|
183
|
+
release.summary 'Create & deploy new releases'
|
|
184
|
+
# b - RELEASE BLUFIN
|
|
185
|
+
release.command :blufin, :aliases => [:b] do |release_blufin|
|
|
186
|
+
release_blufin.summary 'Create and deploy the latest version of Blufin (along with all the gems, lambdas, etc.)'
|
|
187
|
+
release_blufin.action do |opts, args|
|
|
188
|
+
AppCommand::ReleaseBlufin.new(opts, args).execute
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
# RELEASE (Default)
|
|
192
|
+
release.action do
|
|
193
|
+
system("#{App::GEM_NAME} R -h")
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# p - PROJECT
|
|
198
|
+
app.command :project, :aliases => [:p] do |project|
|
|
199
|
+
project.summary 'Information about Projects'
|
|
200
|
+
# al - PROJECT API LIST
|
|
201
|
+
project.command :api_list, :aliases => [:al] do |project_api_list|
|
|
202
|
+
project_api_list.summary 'List all APIs'
|
|
203
|
+
project_api_list.action do |opts, args|
|
|
204
|
+
AppCommand::APIList.new(opts, args).execute
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
# am - PROJECT API META
|
|
208
|
+
project.command :api_meta, :aliases => [:am] do |project_api_meta|
|
|
209
|
+
project_api_meta.summary 'Display various meta-data about an API'
|
|
210
|
+
project_api_meta.options do |opts|
|
|
211
|
+
opts.opt :show_auto_increment, "Show #{Blufin::Terminal::format_highlight('AUTO_INCREMENT')} columns", :short => '-a', :long => '--show-auto-increment', :type => :boolean
|
|
212
|
+
opts.opt :show_enums, "Show all available #{Blufin::Terminal::format_highlight('ENUMs')} (and their values)", :short => '-e', :long => '--show-enums', :type => :boolean
|
|
213
|
+
opts.opt :show_resources, "Show #{Blufin::Terminal::format_highlight('RESOURCE')} structure #{Blufin::Terminal::format_invalid('@deprecated')}", :short => '-r', :long => '--show-resources', :type => :boolean
|
|
214
|
+
opts.opt :as_json, 'Return meta-data as JSON (might not work for all paths)', :short => '-J', :long => '--as-json', :type => :boolean
|
|
215
|
+
end
|
|
216
|
+
project_api_meta.action do |opts, args|
|
|
217
|
+
AppCommand::APIMeta.new(opts, args).execute
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
# PROJECT (Default)
|
|
221
|
+
project.action do
|
|
222
|
+
system("#{App::GEM_NAME} p -h")
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# x - CONFIG
|
|
227
|
+
app.command :config, :aliases => [:x] do |config|
|
|
228
|
+
config.summary 'Setup your configuration file'
|
|
229
|
+
config.action do
|
|
230
|
+
Blufin::Config::edit_config(App::CONFIG_FILE)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# BLUFIN (Default)
|
|
235
|
+
app.action do
|
|
236
|
+
system("#{App::GEM_NAME} -h")
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
rescue RuntimeError => e
|
|
241
|
+
|
|
242
|
+
Blufin::Terminal::print_exception(e);
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Blufin
|
|
2
|
+
|
|
3
|
+
class ScannerCommon
|
|
4
|
+
|
|
5
|
+
# Gets all non-ignored files in a specific directory (recursively).
|
|
6
|
+
# path = the path from root, IE: /Users/Albert/Repos/repos-blufin/[site-name]/app-infrastructure
|
|
7
|
+
# gitignore = the path (prefix) to ignore as defined in .gitignore, IE: app-infrastructure
|
|
8
|
+
# @return Array (of files)
|
|
9
|
+
def self.get_non_ignored_files(path, extensions, error_handler, gitignore_path = nil)
|
|
10
|
+
raise RuntimeError, "Expected String, instead got: #{path.class}" unless path.is_a?(String)
|
|
11
|
+
raise RuntimeError, "Expected Array, instead got: #{extensions.class}" unless extensions.is_a?(Array)
|
|
12
|
+
raise RuntimeError, "Expected YmlErrorHandler, instead got:#{error_handler.class}" unless error_handler.is_a?(Blufin::YmlErrorHandler)
|
|
13
|
+
raise RuntimeError, "Expected String or Nil, instead got: #{gitignore_path.class}" unless gitignore_path.nil? || gitignore_path.is_a?(String)
|
|
14
|
+
found_files = []
|
|
15
|
+
ignore_paths = []
|
|
16
|
+
scan_path = path
|
|
17
|
+
gitignore_path.gsub(/\A\//, '').gsub(/\/\z/, '') unless gitignore_path.nil?
|
|
18
|
+
unless gitignore_path.nil? || gitignore_path == ''
|
|
19
|
+
gitignore_file = "#{path}/.gitignore"
|
|
20
|
+
scan_path = "#{path}/#{gitignore_path}"
|
|
21
|
+
if Blufin::Files::file_exists(gitignore_file)
|
|
22
|
+
# Adds all ignore paths for .gitignore.
|
|
23
|
+
Blufin::Files::read_file(gitignore_file).each do |line|
|
|
24
|
+
line = line.gsub(/\A\//, '').gsub("\n", '')
|
|
25
|
+
next unless line =~ /\A#{gitignore_path}\//
|
|
26
|
+
ignore_paths << "#{path}/#{line}"
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
# Add error if git ignore is missing.
|
|
30
|
+
error_handler.add_error(Blufin::YmlErrorHandler::FILE_NOT_FOUND_GITIGNORE, gitignore_file, nil, nil, gitignore_file)
|
|
31
|
+
return found_files
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
# Gets all files (which are not ignored).
|
|
35
|
+
Blufin::Files::get_files_in_dir("#{scan_path}").each do |file|
|
|
36
|
+
next if is_in_ignore_path(file, ignore_paths)
|
|
37
|
+
matches_extension = false
|
|
38
|
+
extensions.each { |extension| matches_extension = true if file =~ /\.#{extension}\z/ }
|
|
39
|
+
next unless matches_extension
|
|
40
|
+
found_files << file
|
|
41
|
+
end
|
|
42
|
+
found_files
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Takes a path and swaps it from classpath to test-path.
|
|
46
|
+
# @return String
|
|
47
|
+
def self.swap_classpath_for_testpath(site, file)
|
|
48
|
+
raise RuntimeError, "Expected String, instead got: #{file.class}" unless file.is_a?(String)
|
|
49
|
+
site = Blufin::SiteResolver::validate_site(site)
|
|
50
|
+
site_name = Blufin::SiteResolver::get_site_name(site)
|
|
51
|
+
site_domain = Blufin::SiteResolver::get_site_domain(site)
|
|
52
|
+
site_domain_gsub = site_domain.strip == '' ? '' : "#{site_domain.gsub('.', '/')}\\/"
|
|
53
|
+
begin
|
|
54
|
+
matches = file.match(/\/#{site_name}-(#{Blufin::SiteServices::REGEX_JAVA})\/src\/main\/java\/#{site_domain_gsub}#{site_name.gsub('-', '/')}\//)
|
|
55
|
+
matches = matches[0].gsub(/\A\//, '').gsub(/\/\z/, '')
|
|
56
|
+
matches = matches.split('/')
|
|
57
|
+
service = matches[0]
|
|
58
|
+
swap_path = "/#{service}/src/main/java/"
|
|
59
|
+
swap_for = "/#{service}/src/test/java/"
|
|
60
|
+
raise RuntimeError, "Unable to find swap_path: #{swap_path}" unless file =~ /#{swap_path}/
|
|
61
|
+
return file.gsub(swap_path, swap_for)
|
|
62
|
+
rescue => e
|
|
63
|
+
puts e.message
|
|
64
|
+
raise RuntimeError, "Failed to swap_classpath_for_testpath() with file: #{file}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
# Checks if file is in ignore_paths Array. Only used internally by this class.
|
|
71
|
+
# @return Boolean
|
|
72
|
+
def self.is_in_ignore_path(file, ignore_paths)
|
|
73
|
+
ignore_paths.each { |line|
|
|
74
|
+
line = line.gsub(/\*\*\/\*\z/, '')
|
|
75
|
+
line = line.gsub(/\*\*\//, '')
|
|
76
|
+
line = line.gsub(/\*\z/, '')
|
|
77
|
+
return true if file.strip =~ /\A#{line.strip}/ }
|
|
78
|
+
false
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
module Blufin
|
|
2
|
+
|
|
3
|
+
class ScannerJava
|
|
4
|
+
|
|
5
|
+
NAME = 'name'
|
|
6
|
+
PATH = 'path'
|
|
7
|
+
|
|
8
|
+
TEST = 'test'
|
|
9
|
+
TEST_REQUIRED = 'test_required'
|
|
10
|
+
TEST_NOT_RELATED_TO_CLASS = 'test_not_related_to_class'
|
|
11
|
+
|
|
12
|
+
TYPE = 'type'
|
|
13
|
+
TYPE_CLASS = 'type_class'
|
|
14
|
+
TYPE_CLASS_ABSTRACT = 'type_class_abstract'
|
|
15
|
+
TYPE_ENUM = 'type_enum'
|
|
16
|
+
TYPE_INTERFACE = 'type_interface'
|
|
17
|
+
|
|
18
|
+
@@scanned_classes = {}
|
|
19
|
+
|
|
20
|
+
# Returns a Hash containing info about the Java class.
|
|
21
|
+
# @return void
|
|
22
|
+
def self.scan(file, site, error_handler)
|
|
23
|
+
return @@scanned_classes[file] unless @@scanned_classes[file].nil?
|
|
24
|
+
raise RuntimeError, "Expected String, instead got: #{file.class}" unless file.is_a?(String)
|
|
25
|
+
raise RuntimeError, "This method only accepts .java files. You passed: #{file}" unless file =~ /\.java\z/
|
|
26
|
+
site = Blufin::SiteResolver::validate_site(site)
|
|
27
|
+
site_path = Blufin::SiteResolver::get_site_location(site)
|
|
28
|
+
fps = Blufin::YmlCommon::split_to_path_file(file, site_path)
|
|
29
|
+
info = {
|
|
30
|
+
NAME => fps[1],
|
|
31
|
+
PATH => fps[0],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Is this a test?
|
|
35
|
+
info[TEST] = (file =~ /\/src\/test\//) ? true : false
|
|
36
|
+
info[TEST_REQUIRED] = true unless info[TEST]
|
|
37
|
+
|
|
38
|
+
@test_required = false
|
|
39
|
+
@test_not_required = false
|
|
40
|
+
@test_not_related_to_class = false
|
|
41
|
+
|
|
42
|
+
Blufin::Files::read_file(file).each do |line|
|
|
43
|
+
get_java_class_type(info, line, file) if info[TYPE].nil?
|
|
44
|
+
get_java_test_required(info, line) if info[TEST_REQUIRED]
|
|
45
|
+
get_java_test_not_related_to_class(info, line) if info[TEST]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Errors
|
|
49
|
+
tests_annotations_found = []
|
|
50
|
+
tests_annotations_found << Blufin::SiteServices::ANNOTATION_TEST_REQUIRED if @test_required
|
|
51
|
+
tests_annotations_found << Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED if @test_not_required
|
|
52
|
+
error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_ONE_OR_ANOTHER, file, nil, nil, [Blufin::SiteServices::ANNOTATION_TEST_REQUIRED, Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED].inspect) if @test_required && @test_not_required
|
|
53
|
+
error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_NOT_EXPECTED, file, nil, nil, tests_annotations_found.inspect) if info[TEST] && tests_annotations_found.any?
|
|
54
|
+
error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_NOT_EXPECTED, file, nil, nil, Blufin::SiteServices::ANNOTATION_TEST_NOT_RELATED_TO_CLASS.inspect) if info[TEST] == false && @test_not_related_to_class
|
|
55
|
+
info[TEST_REQUIRED] = true if @test_required
|
|
56
|
+
info[TEST_REQUIRED] = false if @test_not_required
|
|
57
|
+
raise RuntimeError, "Unrecognized ClassType: #{file}" if info[TYPE].nil?
|
|
58
|
+
@@scanned_classes[file] = info
|
|
59
|
+
info
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
# Gets the Java class TYPE.
|
|
65
|
+
# @return void
|
|
66
|
+
def self.get_java_class_type(info, line, file)
|
|
67
|
+
if line =~ /\Apublic class\s/ || line =~ /\Apublic final class\s/
|
|
68
|
+
info[TYPE] = TYPE_CLASS
|
|
69
|
+
elsif line =~ /\Aclass\s/ || line =~ /\Afinal class\s/
|
|
70
|
+
info[TYPE] = TYPE_CLASS
|
|
71
|
+
# TODO - 05-06-19 - Remove this warning once we have some kind of code-formatter.
|
|
72
|
+
Blufin::Terminal::output("Class in file is not public: #{file}", Blufin::Terminal::MSG_WARNING)
|
|
73
|
+
elsif line =~ /\Apublic abstract class/
|
|
74
|
+
info[TYPE] = TYPE_CLASS_ABSTRACT
|
|
75
|
+
elsif line =~ /\Apublic enum/
|
|
76
|
+
info[TYPE] = TYPE_ENUM
|
|
77
|
+
elsif line =~ /\Apublic interface/
|
|
78
|
+
info[TYPE] = TYPE_INTERFACE
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Looks for @TestRequired, @NoTestRequired annotation.
|
|
83
|
+
# @return void
|
|
84
|
+
def self.get_java_test_required(info, line)
|
|
85
|
+
return if (@test_required || @test_not_required) && !info[TYPE].nil?
|
|
86
|
+
info[TEST_REQUIRED] = false if line =~ /\A#{Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED}/
|
|
87
|
+
info[TEST_REQUIRED] = false if line =~ /\Apublic abstract class/
|
|
88
|
+
@test_required = true if line =~ /\A#{Blufin::SiteServices::ANNOTATION_TEST_REQUIRED}/
|
|
89
|
+
@test_not_required = true if line =~ /\A#{Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED}/
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Looks for @TestNotRelatedToClass annotation.
|
|
93
|
+
# @return void
|
|
94
|
+
def self.get_java_test_not_related_to_class(info, line)
|
|
95
|
+
return if info[TEST_NOT_RELATED_TO_CLASS]
|
|
96
|
+
if line =~ /\A#{Blufin::SiteServices::ANNOTATION_TEST_NOT_RELATED_TO_CLASS}/
|
|
97
|
+
info[TEST_NOT_RELATED_TO_CLASS] = true
|
|
98
|
+
@test_not_related_to_class = true
|
|
99
|
+
else
|
|
100
|
+
info[TEST_NOT_RELATED_TO_CLASS] = false
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|