Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #358: Fallback for detecting java projects #367

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2312,3 +2321,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
}
Loading