Skip to content

Commit

Permalink
Adding maven global settings for selecting correct cache dir
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <shawn@hurley.page>
  • Loading branch information
shawn-hurley committed Oct 29, 2024
1 parent 9264d55 commit 70aef36
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (r *Analyzer) options(output, depOutput string) (options command.Options, e
if err != nil {
return
}
err = r.MavenSettings.UpdateSettings(settings)
if err != nil {
return
}
err = settings.Write()
if err != nil {
return
Expand Down
11 changes: 11 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type Data struct {
Rules Rules `json:"rules"`
// Tagger options.
Tagger Tagger `json:"tagger"`
// MavenSettings options
MavenSettings MavenGlobalSettings `json:"mavenSettings,omitempty"`
}

// main
Expand Down Expand Up @@ -88,6 +90,11 @@ func main() {
return
}
//
// Create the maven user settings.
d.MavenSettings = MavenGlobalSettings{
MavenRepoLocation: M2Dir,
SharedDir: SharedDir,
}
// SSH
agent := ssh.Agent{}
err = agent.Start()
Expand All @@ -104,6 +111,10 @@ func main() {
if err != nil {
return
}
err = d.MavenSettings.Build()
if err != nil {
return
}
//
// Run the analyzer.
analyzer := Analyzer{}
Expand Down
49 changes: 49 additions & 0 deletions cmd/maven_settings.go
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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/gin-gonic/gin v1.9.1
github.com/konveyor/analyzer-lsp v0.4.0-alpha.1.0.20240603131628-bc4ff29956a2
github.com/konveyor/tackle2-addon v0.6.0-alpha.1.0.20241010185506-67652f48f2f2
github.com/konveyor/tackle2-addon v0.6.0-alpha.2
github.com/konveyor/tackle2-hub v0.5.1-0.20240926152344-e15a8a4fbf23
github.com/onsi/gomega v1.27.6
github.com/rogpeppe/go-internal v1.10.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ github.com/konveyor/analyzer-lsp v0.4.0-alpha.1.0.20240603131628-bc4ff29956a2 h1
github.com/konveyor/analyzer-lsp v0.4.0-alpha.1.0.20240603131628-bc4ff29956a2/go.mod h1:GXkSykQ84oE1SyMvFko9s9wRn/FMdl4efLLWSjMX2nU=
github.com/konveyor/tackle2-addon v0.6.0-alpha.1.0.20241010185506-67652f48f2f2 h1:xmH1Uw9mGajwXOSsyP3D9j+mHO+7/ukZOyqKKTqjFg0=
github.com/konveyor/tackle2-addon v0.6.0-alpha.1.0.20241010185506-67652f48f2f2/go.mod h1:1cHTnmMGtYzv0GIMiyEMPkJe+hOlzbhxwRal5e7Mog0=
github.com/konveyor/tackle2-addon v0.6.0-alpha.2 h1:1WV7D9KwaVYG1xMKuRuSc84+ZVBWcPm1L+kednlW1zA=
github.com/konveyor/tackle2-addon v0.6.0-alpha.2/go.mod h1:1cHTnmMGtYzv0GIMiyEMPkJe+hOlzbhxwRal5e7Mog0=
github.com/konveyor/tackle2-hub v0.5.1-0.20240926152344-e15a8a4fbf23 h1:EnSIrmEte86RvQx8/QsCnm/Wo/F+z0NMowTdoZJpUhc=
github.com/konveyor/tackle2-hub v0.5.1-0.20240926152344-e15a8a4fbf23/go.mod h1:PeqkGgjIbCjaK/zudHGcBG4jB3Wbyi+lAIDLUjgjbMI=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down

0 comments on commit 70aef36

Please sign in to comment.