Skip to content

Commit

Permalink
✨ pass maven settings for analysis
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <[email protected]>
  • Loading branch information
pranavgaikwad committed Sep 5, 2023
1 parent ba28b05 commit 374e4ba
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type analyzeCommand struct {
listTargets bool
skipStaticReport bool
analyzeKnownLibraries bool
mavenSettingsFile string
sources []string
targets []string
input string
Expand Down Expand Up @@ -133,6 +134,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
analyzeCommand.Flags().StringVarP(&analyzeCmd.output, "output", "o", "", "path to the directory for analysis output")
analyzeCommand.Flags().BoolVar(&analyzeCmd.skipStaticReport, "skip-static-report", false, "do not generate static report")
analyzeCommand.Flags().BoolVar(&analyzeCmd.analyzeKnownLibraries, "analyze-known-libraries", false, "analyze known open-source libraries")
analyzeCommand.Flags().StringVar(&analyzeCmd.mavenSettingsFile, "maven-settings", "", "path to a custom maven settings file to use")
analyzeCommand.Flags().StringVarP(&analyzeCmd.mode, "mode", "m", string(provider.FullAnalysisMode), "analysis mode. Must be one of 'full' or 'source-only'")

return analyzeCommand
Expand Down Expand Up @@ -175,13 +177,19 @@ func (a *analyzeCommand) Validate() error {
a.mode != string(provider.SourceOnlyAnalysisMode) {
return fmt.Errorf("mode must be one of 'full' or 'source-only'")
}
if _, err := os.Stat(a.mavenSettingsFile); a.mavenSettingsFile != "" && err != nil {
return fmt.Errorf("%w failed to stat maven settings file at path %s", err, a.mavenSettingsFile)
}
// try to get abs path, if not, continue with relative path
if absPath, err := filepath.Abs(a.output); err == nil {
a.output = absPath
}
if absPath, err := filepath.Abs(a.input); err == nil {
a.input = absPath
}
if absPath, err := filepath.Abs(a.mavenSettingsFile); err == nil {
a.mavenSettingsFile = absPath
}
return nil
}

Expand Down Expand Up @@ -312,6 +320,8 @@ func listOptionsFromLabels(sl []string, label string) {
}

func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
vols := map[string]string{}

tempDir, err := os.MkdirTemp("", "analyze-config-")
if err != nil {
a.log.V(1).Error(err, "failed creating temp dir", "dir", tempDir)
Expand All @@ -328,6 +338,12 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
otherProvsMountPath = filepath.Dir(otherProvsMountPath)
}

var mavenSettingsFile string
if a.mavenSettingsFile != "" {
mavenSettingsFile = fmt.Sprintf("%s/%s", ConfigMountPath, "settings.xml")
vols[a.mavenSettingsFile] = mavenSettingsFile
}

provConfig := []provider.Config{
{
Name: "go",
Expand All @@ -354,6 +370,7 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
ProviderSpecificConfig: map[string]interface{}{
"bundles": "/jdtls/java-analyzer-bundle/java-analyzer-bundle.core/target/java-analyzer-bundle.core-1.0.0-SNAPSHOT.jar",
"depOpenSourceLabelsFile": "/usr/local/etc/maven.default.index",
"mavenSettingsFile": mavenSettingsFile,
provider.LspServerPathConfigKey: "/jdtls/bin/jdtls",
},
},
Expand All @@ -379,9 +396,8 @@ func (a *analyzeCommand) getConfigVolumes() (map[string]string, error) {
a.log.V(1).Error(err, "failed to write provider config", "dir", tempDir, "file", "settings.json")
return nil, err
}
return map[string]string{
tempDir: ConfigMountPath,
}, nil
vols[tempDir] = ConfigMountPath
return vols, nil
}

func (a *analyzeCommand) getRulesVolumes() (map[string]string, error) {
Expand Down

0 comments on commit 374e4ba

Please sign in to comment.