Skip to content

Commit

Permalink
global settings file for java provider
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed Oct 30, 2024
1 parent efb7857 commit 6db200d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
BUNDLES_INIT_OPTION = "bundles"
WORKSPACE_INIT_OPTION = "workspace"
MVN_SETTINGS_FILE_INIT_OPTION = "mavenSettingsFile"
GLOBAL_SETTINGS_INIT_OPTION = "mavenCacheDir"
JVM_MAX_MEM_INIT_OPTION = "jvmMaxMem"
)

Expand Down Expand Up @@ -237,6 +238,17 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
if !ok {
mavenSettingsFile = ""
}
var globalSettingsFile string
var returnError error
globalM2, ok := config.ProviderSpecificConfig[GLOBAL_SETTINGS_INIT_OPTION].(string)
if !ok {
globalM2 = ""
} else {
globalSettingsFile, returnError = p.BuildSettingsFile(globalM2)
if returnError != nil {
return nil, additionalBuiltinConfig, returnError
}
}

lspServerPath, ok := config.ProviderSpecificConfig[provider.LspServerPathConfigKey].(string)
if !ok || lspServerPath == "" {
Expand Down Expand Up @@ -387,6 +399,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
depToLabels: map[string]*depLabelItem{},
isLocationBinary: isBinary,
mvnSettingsFile: mavenSettingsFile,
globalSettings: globalSettingsFile,
depsLocationCache: make(map[string]int),
includedPaths: provider.GetIncludedPathsFromConfig(config, false),
}
Expand Down Expand Up @@ -884,3 +897,30 @@ func (p *javaProvider) GetDependencies(ctx context.Context) (map[uri.URI][]*prov
func (p *javaProvider) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
return provider.FullDepDAGResponse(ctx, p.clients)
}

func (p *javaProvider) BuildSettingsFile(m2CacheDir string) (settingsFile string, err error) {
fileContentTemplate := `
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<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)))
if err != nil {
return "", err
}
}

return settingsFilePath, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type javaServiceClient struct {
depToLabels map[string]*depLabelItem
isLocationBinary bool
mvnSettingsFile string
globalSettings string
depsMutex sync.RWMutex
depsCache map[uri.URI][]*provider.Dep
depsLocationCache map[string]int
Expand Down Expand Up @@ -241,7 +242,8 @@ func (p *javaServiceClient) initialization(ctx context.Context) {
"java": map[string]interface{}{
"configuration": map[string]interface{}{
"maven": map[string]interface{}{
"userSettings": p.mvnSettingsFile,
"userSettings": p.mvnSettingsFile,
"globalSettings": p.globalSettings,
},
},
"autobuild": map[string]interface{}{
Expand Down

0 comments on commit 6db200d

Please sign in to comment.