diff --git a/src/analyzer/analyzers/analyzer_armeria.cr b/src/analyzer/analyzers/analyzer_armeria.cr index 875d4782..618454b7 100644 --- a/src/analyzer/analyzers/analyzer_armeria.cr +++ b/src/analyzer/analyzers/analyzer_armeria.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_cs_aspnet_mvc.cr b/src/analyzer/analyzers/analyzer_cs_aspnet_mvc.cr index 06753f94..ec4665c4 100644 --- a/src/analyzer/analyzers/analyzer_cs_aspnet_mvc.cr +++ b/src/analyzer/analyzers/analyzer_cs_aspnet_mvc.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_django.cr b/src/analyzer/analyzers/analyzer_django.cr index 7d52b14d..5030f3b8 100644 --- a/src/analyzer/analyzers/analyzer_django.cr +++ b/src/analyzer/analyzers/analyzer_django.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_example.cr b/src/analyzer/analyzers/analyzer_example.cr index 5fbf2ac9..88bf9058 100644 --- a/src/analyzer/analyzers/analyzer_example.cr +++ b/src/analyzer/analyzers/analyzer_example.cr @@ -19,5 +19,6 @@ end def analyzer_example(options : Hash(Symbol, String)) instance = AnalyzerExample.new(options) + instance.sync_base_path "example" instance.analyze end diff --git a/src/analyzer/analyzers/analyzer_flask.cr b/src/analyzer/analyzers/analyzer_flask.cr index 810df6aa..d53826ae 100644 --- a/src/analyzer/analyzers/analyzer_flask.cr +++ b/src/analyzer/analyzers/analyzer_flask.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_go_echo.cr b/src/analyzer/analyzers/analyzer_go_echo.cr index 856ee2be..a3aba66c 100644 --- a/src/analyzer/analyzers/analyzer_go_echo.cr +++ b/src/analyzer/analyzers/analyzer_go_echo.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_go_gin.cr b/src/analyzer/analyzers/analyzer_go_gin.cr index 9f0c2189..d269ca8f 100644 --- a/src/analyzer/analyzers/analyzer_go_gin.cr +++ b/src/analyzer/analyzers/analyzer_go_gin.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_jsp.cr b/src/analyzer/analyzers/analyzer_jsp.cr index cd930c04..dd3754da 100644 --- a/src/analyzer/analyzers/analyzer_jsp.cr +++ b/src/analyzer/analyzers/analyzer_jsp.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_kemal.cr b/src/analyzer/analyzers/analyzer_kemal.cr index 74297a04..428783a4 100644 --- a/src/analyzer/analyzers/analyzer_kemal.cr +++ b/src/analyzer/analyzers/analyzer_kemal.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_oas2.cr b/src/analyzer/analyzers/analyzer_oas2.cr index 21a9c306..2904d85b 100644 --- a/src/analyzer/analyzers/analyzer_oas2.cr +++ b/src/analyzer/analyzers/analyzer_oas2.cr @@ -88,5 +88,6 @@ end def analyzer_oas2(options : Hash(Symbol, String)) instance = AnalyzerOAS2.new(options) + instance.sync_base_path "oas2" instance.analyze end diff --git a/src/analyzer/analyzers/analyzer_oas3.cr b/src/analyzer/analyzers/analyzer_oas3.cr index f65e8ed7..27e1e61b 100644 --- a/src/analyzer/analyzers/analyzer_oas3.cr +++ b/src/analyzer/analyzers/analyzer_oas3.cr @@ -139,5 +139,6 @@ end def analyzer_oas3(options : Hash(Symbol, String)) instance = AnalyzerOAS3.new(options) + instance.sync_base_path "oas3" instance.analyze end diff --git a/src/analyzer/analyzers/analyzer_php_pure.cr b/src/analyzer/analyzers/analyzer_php_pure.cr index 89420cbe..fa7cc99d 100644 --- a/src/analyzer/analyzers/analyzer_php_pure.cr +++ b/src/analyzer/analyzers/analyzer_php_pure.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_rails.cr b/src/analyzer/analyzers/analyzer_rails.cr index 6b7c5a31..e0c0ee71 100644 --- a/src/analyzer/analyzers/analyzer_rails.cr +++ b/src/analyzer/analyzers/analyzer_rails.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_raml.cr b/src/analyzer/analyzers/analyzer_raml.cr index 60c67597..fd8d4b48 100644 --- a/src/analyzer/analyzers/analyzer_raml.cr +++ b/src/analyzer/analyzers/analyzer_raml.cr @@ -58,5 +58,6 @@ end def analyzer_raml(options : Hash(Symbol, String)) instance = AnalyzerRAML.new(options) + instance.sync_base_path "raml" instance.analyze end diff --git a/src/analyzer/analyzers/analyzer_sinatra.cr b/src/analyzer/analyzers/analyzer_sinatra.cr index c6e91c88..84614b88 100644 --- a/src/analyzer/analyzers/analyzer_sinatra.cr +++ b/src/analyzer/analyzers/analyzer_sinatra.cr @@ -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 diff --git a/src/analyzer/analyzers/analyzer_spring.cr b/src/analyzer/analyzers/analyzer_spring.cr index 9a237b8e..8daa980a 100644 --- a/src/analyzer/analyzers/analyzer_spring.cr +++ b/src/analyzer/analyzers/analyzer_spring.cr @@ -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 diff --git a/src/detector/detector.cr b/src/detector/detector.cr index a3d01bcf..bd78dff4 100644 --- a/src/detector/detector.cr +++ b/src/detector/detector.cr @@ -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 diff --git a/src/detector/detectors/crystal_kemal.cr b/src/detector/detectors/crystal_kemal.cr index 5374a075..b52370bf 100644 --- a/src/detector/detectors/crystal_kemal.cr +++ b/src/detector/detectors/crystal_kemal.cr @@ -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 diff --git a/src/detector/detectors/cs_aspnet_mvc.cr b/src/detector/detectors/cs_aspnet_mvc.cr index f5f7e24b..eae9ff86 100644 --- a/src/detector/detectors/cs_aspnet_mvc.cr +++ b/src/detector/detectors/cs_aspnet_mvc.cr @@ -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 diff --git a/src/detector/detectors/go_echo.cr b/src/detector/detectors/go_echo.cr index c5a77418..bec7b0e7 100644 --- a/src/detector/detectors/go_echo.cr +++ b/src/detector/detectors/go_echo.cr @@ -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 diff --git a/src/detector/detectors/go_gin.cr b/src/detector/detectors/go_gin.cr index 90fddbf9..78ff64a3 100644 --- a/src/detector/detectors/go_gin.cr +++ b/src/detector/detectors/go_gin.cr @@ -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 diff --git a/src/detector/detectors/java_armeria.cr b/src/detector/detectors/java_armeria.cr index 773f8d16..b94e802d 100644 --- a/src/detector/detectors/java_armeria.cr +++ b/src/detector/detectors/java_armeria.cr @@ -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 diff --git a/src/detector/detectors/java_spring.cr b/src/detector/detectors/java_spring.cr index 766e635b..35917f60 100644 --- a/src/detector/detectors/java_spring.cr +++ b/src/detector/detectors/java_spring.cr @@ -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 diff --git a/src/detector/detectors/kotlin_spring.cr b/src/detector/detectors/kotlin_spring.cr index 3ea4cffc..40d73cb7 100644 --- a/src/detector/detectors/kotlin_spring.cr +++ b/src/detector/detectors/kotlin_spring.cr @@ -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 diff --git a/src/detector/detectors/ruby_rails.cr b/src/detector/detectors/ruby_rails.cr index 4dc665ff..e00d7676 100644 --- a/src/detector/detectors/ruby_rails.cr +++ b/src/detector/detectors/ruby_rails.cr @@ -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 diff --git a/src/detector/detectors/ruby_sinatra.cr b/src/detector/detectors/ruby_sinatra.cr index 19b6e06e..655ba699 100644 --- a/src/detector/detectors/ruby_sinatra.cr +++ b/src/detector/detectors/ruby_sinatra.cr @@ -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 diff --git a/src/models/analyzer.cr b/src/models/analyzer.cr index a4dd47fc..b6d27cc8 100644 --- a/src/models/analyzer.cr +++ b/src/models/analyzer.cr @@ -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 diff --git a/src/models/detector.cr b/src/models/detector.cr index e61588be..6a05d2d8 100644 --- a/src/models/detector.cr +++ b/src/models/detector.cr @@ -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 @@ -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) @@ -33,5 +47,5 @@ class Detector {% end %} end - define_getter_methods [result, base_path, url, scope, logger] + define_getter_methods [name, logger] end