Skip to content

Commit

Permalink
Validate mvn and openjdk & fix list providers for containerless mode (#…
Browse files Browse the repository at this point in the history
…374)

validate mvn and openjdk

Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan authored Nov 14, 2024
1 parent 0666e41 commit 9ab5f64
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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

0 comments on commit 9ab5f64

Please sign in to comment.