Skip to content

Commit

Permalink
Fix static report URL, validate files, set NodeJS provider (#269)
Browse files Browse the repository at this point in the history
set nodejs provider, fix static report url, validate files

Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan authored Jun 25, 2024
1 parent 1300c6e commit f6f8cce
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f6f8cce

Please sign in to comment.