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

🐛 Move mvn global settings file #714

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
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
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
}
}
settingsFilePath := filepath.Join(homeDir, ".analyze", "globalSettings.xml")
err = os.Mkdir(filepath.Join(homeDir, ".analyze"), 0777)
if err != nil && !errors.Is(err, os.ErrExist) {
return "", err
}
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
}
Loading