diff --git a/cmd/analyze.go b/cmd/analyze.go index ff2a507..b31eaa4 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -69,15 +69,24 @@ var ( } ) +// supported providers const ( javaProvider = "java" goProvider = "go" pythonProvider = "python" - nodeJSProvider = "javascript" + nodeJSProvider = "nodejs" dotnetProvider = "dotnet" dotnetFrameworkProvider = "dotnetframework" ) +// valid java file extensions +const ( + JavaArchive = ".jar" + WebArchive = ".war" + EnterpriseArchive = ".ear" + ClassFile = ".class" +) + // provider config options const ( mavenSettingsFile = "mavenSettingsFile" @@ -374,6 +383,14 @@ func (a *analyzeCommand) Validate(ctx context.Context) error { // when input isn't a dir, it's pointing to a binary // we need abs path to mount the file correctly if !stat.Mode().IsDir() { + // validate file types + fileExt := filepath.Ext(a.input) + switch fileExt { + case JavaArchive, WebArchive, EnterpriseArchive, ClassFile: + a.log.V(5).Info("valid java file found") + default: + return fmt.Errorf("invalid file type %v", fileExt) + } a.input, err = filepath.Abs(a.input) if err != nil { return fmt.Errorf("%w failed to get absolute path for input file %s", err, a.input) @@ -489,7 +506,17 @@ func (a *analyzeCommand) setProviders(components []model.Component, foundProvide } } } - foundProviders = append(foundProviders, strings.ToLower(l.Name)) + if l.Name == "JavaScript" { + for _, item := range l.Tools { + if item == "NodeJs" || item == "Node.js" || item == "nodejs" { + foundProviders = append(foundProviders, nodeJSProvider) + // only need one instance of provider + break + } + } + } else { + foundProviders = append(foundProviders, strings.ToLower(l.Name)) + } } } return foundProviders, nil @@ -1561,8 +1588,7 @@ func (a *analyzeCommand) GenerateStaticReport(ctx context.Context) error { return err } uri := uri.File(filepath.Join(a.output, "static-report", "index.html")) - cleanedURI := filepath.Clean(string(uri)) - a.log.Info("Static report created. Access it at this URL:", "URL", cleanedURI) + a.log.Info("Static report created. Access it at this URL:", "URL", string(uri)) return nil }