Skip to content

Commit

Permalink
🐛 Move mvn global settings file (#714)
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan authored Nov 4, 2024
1 parent f14f470 commit fbacb9c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions external-providers/java-external-provider/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ FROM quay.io/konveyor/jdtls-server-base

COPY --from=builder /java-provider/java-external-provider /usr/local/bin/java-external-provider

ENV HOME /addon
EXPOSE 14651
WORKDIR /addon
ENTRYPOINT ["java-external-provider", "--port", "14651"]
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
}

0 comments on commit fbacb9c

Please sign in to comment.