Skip to content

Commit

Permalink
✨ Add settings file option to openrewrite (#141)
Browse files Browse the repository at this point in the history
* Add settings file option to openrewrite

Maven settings.xml file can be now specified as parameter for kantra
transform openrewrite (that uses maven for its execution).

Fixes: #19

Signed-off-by: Marek Aufart <[email protected]>

* Update readme

Signed-off-by: Marek Aufart <[email protected]>

---------

Signed-off-by: Marek Aufart <[email protected]>
  • Loading branch information
aufi authored Jan 16, 2024
1 parent e1028ae commit 86942ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ Usage:
kantra transform openrewrite [flags]

Flags:
-g, --goal string target goal (default "dryRun")
-h, --help help for openrewrite
-i, --input string path to application source code directory
-l, --list-targets list all available OpenRewrite recipes
-t, --target string target openrewrite recipe to use. Run --list-targets to get a list of packaged recipes.
-g, --goal string target goal (default "dryRun")
-h, --help help for openrewrite
-i, --input string path to application source code directory
-l, --list-targets list all available OpenRewrite recipes
-s, --maven-settings string path to a custom maven settings file to use
-t, --target string target openrewrite recipe to use. Run --list-targets to get a list of packaged recipes.

Global Flags:
--log-level int log level (default 5)
Expand Down
22 changes: 15 additions & 7 deletions cmd/openrewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (
)

type openRewriteCommand struct {
listTargets bool
input string
target string
goal string
miscOpts string
log logr.Logger
cleanup bool
listTargets bool
input string
target string
goal string
miscOpts string
log logr.Logger
cleanup bool
mavenSettingsFile string
}

func NewOpenRewriteCommand(log logr.Logger) *cobra.Command {
Expand Down Expand Up @@ -58,6 +59,7 @@ func NewOpenRewriteCommand(log logr.Logger) *cobra.Command {
openRewriteCommand.Flags().StringVarP(&openRewriteCmd.target, "target", "t", "", "target openrewrite recipe to use. Run --list-targets to get a list of packaged recipes.")
openRewriteCommand.Flags().StringVarP(&openRewriteCmd.goal, "goal", "g", "dryRun", "target goal")
openRewriteCommand.Flags().StringVarP(&openRewriteCmd.input, "input", "i", "", "path to application source code directory")
openRewriteCommand.Flags().StringVarP(&openRewriteCmd.mavenSettingsFile, "maven-settings", "s", "", "path to a custom maven settings file to use")

return openRewriteCommand
}
Expand Down Expand Up @@ -143,6 +145,12 @@ func (o *openRewriteCommand) Run(ctx context.Context) error {
}
o.log.Info("executing openrewrite recipe",
"recipe", o.target, "input", o.input, "args", strings.Join(args, " "))

if o.mavenSettingsFile != "" {
o.log.Info("using custom maven settings file", "path", o.mavenSettingsFile)
args = append(args, "-s", o.mavenSettingsFile)
}

err := NewContainer(o.log).Run(
ctx,
WithEntrypointArgs(args...),
Expand Down

0 comments on commit 86942ac

Please sign in to comment.