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

Validate mvn and openjdk & fix list providers for containerless mode #374

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions cmd/analyze-bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
"io"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -212,6 +215,30 @@ func (a *analyzeCommand) RunAnalysisContainerless(ctx context.Context) error {
}

func (a *analyzeCommand) ValidateContainerless(ctx context.Context) error {
// validate mvn and openjdk install
_, mvnErr := exec.LookPath("mvn")
if mvnErr != nil {
return fmt.Errorf("%w cannot find requirement maven; ensure maven is installed", mvnErr)

}
cmd := exec.Command("java", "-version")
output, err := cmd.CombinedOutput()
if err != nil {
return err
}
if strings.Contains(string(output), "openjdk") {
re := regexp.MustCompile(`openjdk version "(.*?)"`)
match := re.FindStringSubmatch(string(output))
jdkVersionStr := strings.Split(match[1], ".")
jdkVersionInt, err := strconv.Atoi(jdkVersionStr[0])
if err != nil {
return err
}
if jdkVersionInt < 17 {
return fmt.Errorf("cannot find requirement openjdk17+; ensure openjdk17+ is installed")
}
}

// Validate .kantra in home directory and its content (containerless)
requiredDirs := []string{a.kantraDir, filepath.Join(a.kantraDir, RulesetsLocation), filepath.Join(a.kantraDir, JavaBundlesLocation), filepath.Join(a.kantraDir, JDTLSBinLocation)}
for _, path := range requiredDirs {
Expand Down
4 changes: 4 additions & 0 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {

// ***** RUN CONTAINERLESS MODE *****
if Settings.RunLocal {
if analyzeCmd.listProviders {
log.Info("\n containerless analysis mode set; only java provider supported")
return nil
}
log.Info("\n running analysis in containerless mode")
if analyzeCmd.listSources || analyzeCmd.listTargets {
err := analyzeCmd.listLabelsContainerless(ctx)
Expand Down
Loading