-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding maven global settings for selecting correct cache dir
Signed-off-by: Shawn Hurley <shawn@hurley.page>
- Loading branch information
1 parent
9264d55
commit 70aef36
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
) | ||
|
||
// Settings - provider settings file. | ||
type MavenGlobalSettings struct { | ||
MavenRepoLocation string | ||
SharedDir string | ||
} | ||
|
||
const GLOBAL_MAVEN_SETTINGS_KEY = "mavenGlobalSettings" | ||
const GLOBAL_MAVEN_FILE_NAME = "globalSettings.xml" | ||
|
||
func (m *MavenGlobalSettings) Build() (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>%s</localRepository> | ||
</settings> | ||
` | ||
path := path.Join(m.SharedDir, GLOBAL_MAVEN_FILE_NAME) | ||
f, err := os.Create(path) | ||
if err != nil { | ||
return | ||
} | ||
defer func() { | ||
_ = f.Close() | ||
}() | ||
_, err = f.Write([]byte(fmt.Sprintf(fileContentTemplate, m.MavenRepoLocation))) | ||
return | ||
} | ||
|
||
// Function to update the settings with the maven global config | ||
// to use the correct directory for the maven cache. | ||
func (m *MavenGlobalSettings) UpdateSettings(settings *Settings) (err error) { | ||
for _, config := range settings.content { | ||
for _, initConfig := range config.InitConfig { | ||
if initConfig.ProviderSpecificConfig == nil { | ||
initConfig.ProviderSpecificConfig = map[string]interface{}{} | ||
} | ||
initConfig.ProviderSpecificConfig[GLOBAL_MAVEN_SETTINGS_KEY] = path.Join(m.SharedDir, GLOBAL_MAVEN_FILE_NAME) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters