Skip to content

Commit

Permalink
Fallback for detecting java projects (#358)
Browse files Browse the repository at this point in the history
fallback for detecting java projects

Signed-off-by: Emily McMullan <emcmulla@redhat.com>
  • Loading branch information
eemcmullan authored Oct 21, 2024
1 parent 00a05da commit 2f22d6d
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,19 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
return err
}
// alizer does not detect certain files such as xml
// in this case we need to run only the analyzer to use builtin provider
// in this case, we can first check for a java project
// if not found, only start builtin provider
if len(foundProviders) == 0 {
analyzeCmd.needsBuiltin = true
return analyzeCmd.RunAnalysis(ctx, xmlOutputDir, analyzeCmd.input)
foundJava, err := analyzeCmd.detectJavaProviderFallback()
if err != nil {
return err
}
if foundJava {
foundProviders = append(foundProviders, javaProvider)
} else {
analyzeCmd.needsBuiltin = true
return analyzeCmd.RunAnalysis(ctx, xmlOutputDir, analyzeCmd.input)
}
}

err = analyzeCmd.setProviderInitInfo(foundProviders)
Expand Down Expand Up @@ -2241,3 +2250,33 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {

return nil
}

func (a *analyzeCommand) detectJavaProviderFallback() (bool, error) {
a.log.V(7).Info("language files not found. Using fallback")
pomPath := filepath.Join(a.input, "pom.xml")
_, err := os.Stat(pomPath)
// some other error
if err != nil && !errors.Is(err, os.ErrNotExist) {
return false, err
}
if err == nil {
return true, nil
}
// try gradle next
gradlePath := filepath.Join(a.input, "build.gradle")
_, err = os.Stat(gradlePath)
// some other error
if err != nil && !errors.Is(err, os.ErrNotExist) {
return false, err

// java project not found
} else if err != nil && errors.Is(err, os.ErrNotExist) {
a.log.V(7).Info("language files not found. Only starting builtin provider")
return false, nil

} else if err == nil {
return true, nil
}

return false, nil
}

0 comments on commit 2f22d6d

Please sign in to comment.