/
configureSDK.go
36 lines (27 loc) · 902 Bytes
/
configureSDK.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package utils
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/hoisie/mustache"
)
// DoConfigureSDK compiles settings.xml template and overrides file
func DoConfigureSDK() {
template := sdkPomXMLTemplate
// compatibility: from artifactory to reposilite
if LookupEnv(txArtifactoryCompat, "0") == "1" {
template = strings.ReplaceAll(template, "-local", "")
fmt.Println("✅ updated repository manager compatibility")
}
data := mustache.Render(template, map[string]string{
txArtifactoryURL: LookupEnv(txArtifactoryURL, "http://localhost:8080/artifactory"),
})
cwd, _ := os.Getwd()
filePath := cwd + sdkPomXMLPath
fileContents, _ := ioutil.ReadFile(filePath)
updatedFileContents := bytes.Replace(fileContents, []byte(sdkPomTag), []byte(data+sdkPomTag), -1)
ioutil.WriteFile(filePath, []byte(updatedFileContents), 0777)
fmt.Println("✅ Updated " + filePath)
}