Skip to content

Commit

Permalink
(#80) Improve multi-tech use of multiple BasePaths
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Sep 12, 2023
1 parent 1f41e00 commit 0ec30cc
Show file tree
Hide file tree
Showing 28 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_armeria.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ end

def analyzer_armeria(options : Hash(Symbol, String))
instance = AnalyzerArmeria.new(options)
instance.sync_base_path "java_armeria"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_cs_aspnet_mvc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ end

def analyzer_cs_aspnet_mvc(options : Hash(Symbol, String))
instance = AnalyzerCsAspNetMvc.new(options)
instance.sync_base_path "c#-aspnet-mvc"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_django.cr
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ end

def analyzer_django(options : Hash(Symbol, String))
instance = AnalyzerDjango.new(options)
instance.sync_base_path "python_django"
instance.analyze
end

Expand Down
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_example.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ end

def analyzer_example(options : Hash(Symbol, String))
instance = AnalyzerExample.new(options)
instance.sync_base_path "example"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_flask.cr
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,6 @@ end

def analyzer_flask(options : Hash(Symbol, String))
instance = AnalyzerFlask.new(options)
instance.sync_base_path "python_flask"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_go_echo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,6 @@ end

def analyzer_go_echo(options : Hash(Symbol, String))
instance = AnalyzerGoEcho.new(options)
instance.sync_base_path "go_echo"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_go_gin.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ end

def analyzer_go_gin(options : Hash(Symbol, String))
instance = AnalyzerGoGin.new(options)
instance.sync_base_path "go_gin"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_jsp.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ end

def analyzer_jsp(options : Hash(Symbol, String))
instance = AnalyzerJsp.new(options)
instance.sync_base_path "java_jsp"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_kemal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ end

def analyzer_kemal(options : Hash(Symbol, String))
instance = AnalyzerKemal.new(options)
instance.sync_base_path "crystal_kemal"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_oas2.cr
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ end

def analyzer_oas2(options : Hash(Symbol, String))
instance = AnalyzerOAS2.new(options)
instance.sync_base_path "oas2"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_oas3.cr
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@ end

def analyzer_oas3(options : Hash(Symbol, String))
instance = AnalyzerOAS3.new(options)
instance.sync_base_path "oas3"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_php_pure.cr
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ end

def analyzer_php_pure(options : Hash(Symbol, String))
instance = AnalyzerPhpPure.new(options)
instance.sync_base_path "php-pure"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_rails.cr
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@ end

def analyzer_rails(options : Hash(Symbol, String))
instance = AnalyzerRails.new(options)
instance.sync_base_path "ruby_rails"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_raml.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ end

def analyzer_raml(options : Hash(Symbol, String))
instance = AnalyzerRAML.new(options)
instance.sync_base_path "raml"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_sinatra.cr
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ end

def analyzer_sinatra(options : Hash(Symbol, String))
instance = AnalyzerSinatra.new(options)
instance.sync_base_path "ruby_sinatra"
instance.analyze
end
1 change: 1 addition & 0 deletions src/analyzer/analyzers/analyzer_spring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@ end

def analyzer_spring(options : Hash(Symbol, String))
instance = AnalyzerSpring.new(options)
instance.sync_base_path "java_spring"
instance.analyze
end
2 changes: 1 addition & 1 deletion src/detector/detector.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def detect_techs(base_path : String, options : Hash(Symbol, String), logger : No
DetectorCrystalKemal, DetectorGoEcho, DetectorJavaJsp, DetectorJavaSpring,
DetectorJsExpress, DetectorPhpPure, DetectorPythonDjango, DetectorPythonFlask,
DetectorRubyRails, DetectorRubySinatra, DetectorOas2, DetectorOas3, DetectorRAML,
DetectorGoGin, DetectorKotlinSpring, DetectorJavaArmeria, DetectorCSharpAspNetMvc
DetectorGoGin, DetectorKotlinSpring, DetectorJavaArmeria, DetectorCSharpAspNetMvc,
])
Dir.glob("#{base_path}/**/*") do |file|
spawn do
Expand Down
1 change: 1 addition & 0 deletions src/detector/detectors/crystal_kemal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class DetectorCrystalKemal < Detector
check = file_contents.includes?("kemalcr/kemal")
check = check && filename.includes?("shard.yml")

set_base_path check, get_parent_path(filename)
check
end

Expand Down
1 change: 1 addition & 0 deletions src/detector/detectors/cs_aspnet_mvc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DetectorCSharpAspNetMvc < Detector
check = check && filename.includes?("packages.config")
check_routeconfig filename, file_contents

set_base_path check, get_parent_path(filename)
check
end

Expand Down
1 change: 1 addition & 0 deletions src/detector/detectors/go_echo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "../../models/detector"
class DetectorGoEcho < Detector
def detect(filename : String, file_contents : String) : Bool
if (filename.includes? "go.mod") && (file_contents.includes? "github.com/labstack/echo")
set_base_path true, get_parent_path(filename)
true
else
false
Expand Down
1 change: 1 addition & 0 deletions src/detector/detectors/go_gin.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "../../models/detector"
class DetectorGoGin < Detector
def detect(filename : String, file_contents : String) : Bool
if (filename.includes? "go.mod") && (file_contents.includes? "github.com/gin-gonic/gin")
set_base_path true, get_parent_path(filename)
true
else
false
Expand Down
2 changes: 2 additions & 0 deletions src/detector/detectors/java_armeria.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class DetectorJavaArmeria < Detector
(filename.includes? "pom.xml") || (filename.includes? "build.gradle") ||
(filename.includes? "build.gradle.kts") || (filename.includes? "settings.gradle.kts")
) && (file_contents.includes? "com.linecorp.armeria")
set_base_path true, get_parent_path(filename)

true
else
false
Expand Down
1 change: 1 addition & 0 deletions src/detector/detectors/java_spring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class DetectorJavaSpring < Detector
if (
(filename.includes? "pom.xml") || (filename.ends_with? "build.gradle")
) && (file_contents.includes? "org.springframework")
set_base_path true, get_parent_path(filename)
true
else
false
Expand Down
2 changes: 2 additions & 0 deletions src/detector/detectors/kotlin_spring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require "../../models/detector"
class DetectorKotlinSpring < Detector
def detect(filename : String, file_contents : String) : Bool
if (filename.ends_with? "build.gradle.kts") && (file_contents.includes? "org.springframework")
set_base_path true, get_parent_path(filename)

true
else
false
Expand Down
1 change: 1 addition & 0 deletions src/detector/detectors/ruby_rails.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DetectorRubyRails < Detector
check = check || file_contents.includes?("gem \"rails\"")
check = check && filename.includes?("Gemfile")

set_base_path check, get_parent_path(filename)
check
end

Expand Down
1 change: 1 addition & 0 deletions src/detector/detectors/ruby_sinatra.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class DetectorRubySinatra < Detector
check = check || file_contents.includes?("gem \"sinatra\"")
check = check && filename.includes?("Gemfile")

set_base_path check, get_parent_path(filename)
check
end

Expand Down
8 changes: 8 additions & 0 deletions src/models/analyzer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class Analyzer
@logger = NoirLogger.new @is_debug, @is_color, @is_log
end

def sync_base_path(key : String)
locator = CodeLocator.instance
base = locator.get("#{key}_basepath")
if base != ""
@base_path = base
end
end

def analyze
# After inheriting the class, write an action code here.
end
Expand Down
20 changes: 17 additions & 3 deletions src/models/detector.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class Detector
@is_color : Bool
@is_log : Bool
@name : String
@base_path : String

def initialize(options : Hash(Symbol, String))
@is_debug = str_to_bool(options[:debug])
@is_color = str_to_bool(options[:color])
@is_log = str_to_bool(options[:nolog])
@name = ""
@base_path = options[:base]

@logger = NoirLogger.new @is_debug, @is_color, @is_log
end
Expand All @@ -21,8 +23,20 @@ class Detector
false
end

def name
@name
def get_parent_path(path : String) : String
path.split("/")[0..-2].join("/")
end

def set_base_path(check : Bool, custom_base : String)
if check
locator = CodeLocator.instance

if custom_base != ""
locator.set("#{@name}_basepath", custom_base)
else
locator.set("#{@name}_basepath", @base_path)
end
end
end

macro define_getter_methods(names)
Expand All @@ -33,5 +47,5 @@ class Detector
{% end %}
end

define_getter_methods [result, base_path, url, scope, logger]
define_getter_methods [name, logger]
end

0 comments on commit 0ec30cc

Please sign in to comment.