Skip to content

Commit

Permalink
Fix openrewrite mount mvn settings (#421)
Browse files Browse the repository at this point in the history
openrewrite mount mvn settings

Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan authored Jan 29, 2025
1 parent b66dc4e commit 8dd8635
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
20 changes: 10 additions & 10 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {

return nil
}
log.Info("--run-local not set. running analysis in container mode")
log.Info("--run-local set to false. Running analysis in container mode")

// ******* RUN CONTAINERS ******
if analyzeCmd.overrideProviderSettings == "" {
Expand Down Expand Up @@ -871,7 +871,7 @@ func (a *analyzeCommand) getRulesVolumes() (map[string]string, error) {
continue
}
destFile := filepath.Join(tempDir, fmt.Sprintf("rules%d.yaml", i))
err := copyFileContents(r, destFile)
err := CopyFileContents(r, destFile)
if err != nil {
a.log.V(1).Error(err, "failed to move rules file", "src", r, "dest", destFile)
return nil, err
Expand Down Expand Up @@ -903,7 +903,7 @@ func (a *analyzeCommand) getRulesVolumes() (map[string]string, error) {
}
destFile := filepath.Join(tempDir, relpath)
a.log.V(5).Info("copying file main", "source", path, "dest", destFile)
err = copyFileContents(path, destFile)
err = CopyFileContents(path, destFile)
if err != nil {
a.log.V(1).Error(err, "failed to move rules file", "src", r, "dest", destFile)
return err
Expand Down Expand Up @@ -969,7 +969,7 @@ func copyFolderContents(src string, dst string) error {
}
} else {
// Copy file
if err := copyFileContents(sourcePath, destinationPath); err != nil {
if err := CopyFileContents(sourcePath, destinationPath); err != nil {
return err
}
}
Expand All @@ -978,7 +978,7 @@ func copyFolderContents(src string, dst string) error {
return nil
}

func copyFileContents(src string, dst string) (err error) {
func CopyFileContents(src string, dst string) (err error) {
source, err := os.Open(src)
if err != nil {
return nil
Expand Down Expand Up @@ -1574,23 +1574,23 @@ func (a *analyzeCommand) moveResults() error {
outputPath := filepath.Join(a.output, "output.yaml")
analysisLogFilePath := filepath.Join(a.output, "analysis.log")
depsPath := filepath.Join(a.output, "dependencies.yaml")
err := copyFileContents(outputPath, fmt.Sprintf("%s.%s", outputPath, a.inputShortName()))
err := CopyFileContents(outputPath, fmt.Sprintf("%s.%s", outputPath, a.inputShortName()))
if err != nil {
return err
}
err = os.Remove(outputPath)
if err != nil {
return err
}
err = copyFileContents(analysisLogFilePath, fmt.Sprintf("%s.%s", analysisLogFilePath, a.inputShortName()))
err = CopyFileContents(analysisLogFilePath, fmt.Sprintf("%s.%s", analysisLogFilePath, a.inputShortName()))
if err != nil {
return err
}
err = os.Remove(analysisLogFilePath)
if err != nil {
return err
}
err = copyFileContents(depsPath, fmt.Sprintf("%s.%s", depsPath, a.inputShortName()))
err = CopyFileContents(depsPath, fmt.Sprintf("%s.%s", depsPath, a.inputShortName()))
if err == nil { // dependencies file presence is optional
err = os.Remove(depsPath)
if err != nil {
Expand Down Expand Up @@ -1683,7 +1683,7 @@ func (a *analyzeCommand) getXMLRulesVolumes(tempRuleDir string) (map[string]stri
mountTempDir = true
xmlFileName := filepath.Base(r)
destFile := filepath.Join(tempRuleDir, xmlFileName)
err := copyFileContents(r, destFile)
err := CopyFileContents(r, destFile)
if err != nil {
a.log.V(1).Error(err, "failed to move rules file from source to destination", "src", r, "dest", destFile)
return nil, err
Expand Down Expand Up @@ -1868,7 +1868,7 @@ func (a *analyzeCommand) mergeProviderSpecificConfig(optionsConf, seenConf map[s
seenConf[k] = absPath
}
// copy file to mount path
err := copyFileContents(v.(string), filepath.Join(tempDir, "settings.xml"))
err := CopyFileContents(v.(string), filepath.Join(tempDir, "settings.xml"))
if err != nil {
a.log.V(1).Error(err, "failed copying maven settings file", "path", v)
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions cmd/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package cmd

import (
"fmt"
"github.com/konveyor/analyzer-lsp/provider"
"path"
"path/filepath"

"github.com/konveyor/analyzer-lsp/provider"
)

type JavaProvider struct {
Expand Down Expand Up @@ -39,7 +40,7 @@ func (p *JavaProvider) GetConfigVolume(a *analyzeCommand, tmpDir string) (provid
}

if a.mavenSettingsFile != "" {
err := copyFileContents(a.mavenSettingsFile, filepath.Join(tmpDir, "settings.xml"))
err := CopyFileContents(a.mavenSettingsFile, filepath.Join(tmpDir, "settings.xml"))
if err != nil {
a.log.V(1).Error(err, "failed copying maven settings file", "path", a.mavenSettingsFile)
return provider.Config{}, err
Expand Down
22 changes: 21 additions & 1 deletion cmd/openrewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path"
"path/filepath"
"strings"

Expand All @@ -12,6 +13,11 @@ import (
"github.com/spf13/cobra"
)

// path in container for maven settings file
const (
settingsFileMountPath = "/tmp/source-app/input"
)

type openRewriteCommand struct {
listTargets bool
input string
Expand Down Expand Up @@ -150,8 +156,22 @@ func (o *openRewriteCommand) Run(ctx context.Context) error {
"recipe", o.target, "input", o.input, "args", strings.Join(args, " "))

if o.mavenSettingsFile != "" {
tempDir, err := os.MkdirTemp("", "openrewrite-settings-")
if err != nil {
o.log.V(1).Error(err, "failed creating temp dir", "dir", tempDir)
return err
}
o.log.V(1).Info("created directory for maven settings file", "dir", tempDir)
defer os.RemoveAll(tempDir)

err = CopyFileContents(o.mavenSettingsFile, filepath.Join(tempDir, "settings.xml"))
if err != nil {
o.log.V(1).Error(err, "failed copying maven settings file", "path", o.mavenSettingsFile)
return err
}
volumes[tempDir] = settingsFileMountPath
o.log.Info("using custom maven settings file", "path", o.mavenSettingsFile)
args = append(args, "-s", o.mavenSettingsFile)
args = append(args, "-s", path.Join(settingsFileMountPath, "settings.xml"))
}
if o.mavenDebugLog {
o.log.Info("Setting Maven log to debug")
Expand Down
2 changes: 1 addition & 1 deletion cmd/shimconvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (w *windupShimCommand) getRulesVolumes(tempRuleDir string) (map[string]stri
mountTempDir = true
xmlFileName := filepath.Base(r)
destFile := filepath.Join(tempRuleDir, xmlFileName)
err := copyFileContents(r, destFile)
err := CopyFileContents(r, destFile)
if err != nil {
w.log.V(1).Error(err, "failed to move rules file from source to destination", "src", r, "dest", destFile)
return nil, err
Expand Down

0 comments on commit 8dd8635

Please sign in to comment.