Skip to content

Commit

Permalink
move mvn global settings file
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <emcmulla@redhat.com>
  • Loading branch information
eemcmullan committed Nov 1, 2024
1 parent f14f470 commit de50ee8
Showing 1 changed file with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -905,22 +906,39 @@ func (p *javaProvider) BuildSettingsFile(m2CacheDir string) (settingsFile string
<localRepository>%v</localRepository>
</settings>
`
var settingsFilePath string
m2Home := os.Getenv("M2_HOME")
if m2Home != "" {
settingsFilePath = filepath.Join(m2Home, "conf", "globalSettings.xml")
f, err := os.Create(settingsFilePath)
if err != nil {
return "", err
}
defer func() {
_ = f.Close()
}()
_, err = f.Write([]byte(fmt.Sprintf(fileContentTemplate, m2CacheDir)))
var homeDir string
set := true
ops := runtime.GOOS
if ops == "linux" {
homeDir, set = os.LookupEnv("XDG_CONFIG_HOME")
}
if ops != "linux" || homeDir == "" || !set {
// on Unix, including macOS, this returns the $HOME environment variable. On Windows, it returns %USERPROFILE%
homeDir, err = os.UserHomeDir()
if err != nil {
return "", err
}
}
err = os.Mkdir(filepath.Join(homeDir, ".analyze"), 0777)
if err != nil {
return "", err
}
settingsFilePath := filepath.Join(homeDir, ".analyze", "globalSettings.xml")
f, err := os.Create(settingsFilePath)
if err != nil {
return "", err
}
defer func() {
_ = f.Close()
}()
err = os.Chmod(settingsFilePath, 0777)
if err != nil {
return "", err
}
_, err = f.Write([]byte(fmt.Sprintf(fileContentTemplate, m2CacheDir)))
if err != nil {
return "", err
}

return settingsFilePath, nil
}

0 comments on commit de50ee8

Please sign in to comment.