This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 745761bc83f6c823e660609c88fb76959fea4cc0 Author: Luca Burgazzoli <lburgazz...@gmail.com> AuthorDate: Wed May 8 15:27:24 2024 +0200 chore: cleanup pkg/util/maven package --- pkg/builder/jib.go | 2 +- pkg/util/maven/maven_command.go | 6 +++--- pkg/util/maven/maven_log.go | 16 ++++++++++------ pkg/util/maven/maven_log_test.go | 2 +- pkg/util/maven/maven_project.go | 6 +++--- pkg/util/maven/maven_repositories.go | 7 +++---- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/pkg/builder/jib.go b/pkg/builder/jib.go index 71c6d6614..87786ee2c 100644 --- a/pkg/builder/jib.go +++ b/pkg/builder/jib.go @@ -135,7 +135,7 @@ func (t *jibTask) Do(ctx context.Context) v1.BuildStatus { cmd.Env = append(cmd.Env, fmt.Sprintf("XDG_CONFIG_HOME=%s/jib", mavenDir)) cmd.Dir = mavenDir - myerror := util.RunAndLog(ctx, cmd, maven.MavenLogHandler, maven.MavenLogHandler) + myerror := util.RunAndLog(ctx, cmd, maven.LogHandler, maven.LogHandler) if myerror != nil { log.Errorf(myerror, "jib integration image containerization did not run successfully") diff --git a/pkg/util/maven/maven_command.go b/pkg/util/maven/maven_command.go index acaeb6c1f..1bc29cf71 100644 --- a/pkg/util/maven/maven_command.go +++ b/pkg/util/maven/maven_command.go @@ -143,7 +143,7 @@ func (c *Command) Do(ctx context.Context) error { return err } - return util.RunAndLog(ctx, cmd, MavenLogHandler, MavenLogHandler) + return util.RunAndLog(ctx, cmd, LogHandler, LogHandler) } func NewContext(buildDir string) Context { @@ -190,7 +190,7 @@ func (c *Context) AddSystemProperty(name string, value string) { } func generateProjectStructure(context Context, project Project) error { - if err := util.WriteFileWithBytesMarshallerContent(context.Path, "pom.xml", project); err != nil { + if err := util.WriteFileWithBytesMarshallerContent(context.Path, "pom.xml", &project); err != nil { return err } @@ -244,7 +244,7 @@ func generateProjectStructure(context Context, project Project) error { func (c *Command) prepareMavenWrapper(ctx context.Context) error { cmd := exec.CommandContext(ctx, "cp", "--recursive", "/usr/share/maven/mvnw/.", ".") cmd.Dir = c.context.Path - return util.RunAndLog(ctx, cmd, MavenLogHandler, MavenLogHandler) + return util.RunAndLog(ctx, cmd, LogHandler, LogHandler) } // ParseGAV decodes the provided Maven GAV into the corresponding Dependency. diff --git a/pkg/util/maven/maven_log.go b/pkg/util/maven/maven_log.go index e47b15cd8..a9d58d2fc 100644 --- a/pkg/util/maven/maven_log.go +++ b/pkg/util/maven/maven_log.go @@ -24,10 +24,9 @@ import ( "github.com/apache/camel-k/v2/pkg/util/log" ) -// nolint: stylecheck type mavenLog struct { Level string `json:"level"` - Ts string `json:"ts"` + TS string `json:"ts"` Logger string `json:"logger"` Msg string `json:"msg"` Class string `json:"class"` @@ -48,10 +47,10 @@ const ( var mavenLogger = log.WithName("maven.build") -func MavenLogHandler(s string) string { - mavenLog, parseError := parseLog(s) +func LogHandler(s string) string { + l, parseError := parseLog(s) if parseError == nil { - normalizeLog(mavenLog) + normalizeLog(l) } else { // Why we are ignoring the parsing errors here: there are a few scenarios where this would likely occur. // For example, if something outside of Maven outputs something (i.e.: the JDK, a misbehaved plugin, @@ -69,8 +68,13 @@ func MavenLogHandler(s string) string { func parseLog(line string) (mavenLog, error) { var l mavenLog + err := json.Unmarshal([]byte(line), &l) - return l, err + if err != nil { + return l, err + } + + return l, nil } func normalizeLog(mavenLog mavenLog) { diff --git a/pkg/util/maven/maven_log_test.go b/pkg/util/maven/maven_log_test.go index 2fa74dd2a..46fadfdb0 100644 --- a/pkg/util/maven/maven_log_test.go +++ b/pkg/util/maven/maven_log_test.go @@ -34,7 +34,7 @@ func TestRunAndLogErrorMvn(t *testing.T) { } cmd := exec.CommandContext(context.Background(), mavenCmd, "package", "-B") - err := util.RunAndLog(context.Background(), cmd, MavenLogHandler, MavenLogHandler) + err := util.RunAndLog(context.Background(), cmd, LogHandler, LogHandler) require.Error(t, err) require.ErrorContains(t, err, "[ERROR] The goal you specified requires a project to execute but there is no POM in this directory") diff --git a/pkg/util/maven/maven_project.go b/pkg/util/maven/maven_project.go index 7eba8f0d0..439109c81 100644 --- a/pkg/util/maven/maven_project.go +++ b/pkg/util/maven/maven_project.go @@ -47,14 +47,14 @@ func NewProjectWithGAV(group string, artifact string, version string) Project { return p } -func (p Project) Command(context Context) *Command { +func (p *Project) Command(context Context) *Command { return &Command{ context: context, - project: p, + project: *p, } } -func (p Project) MarshalBytes() ([]byte, error) { +func (p *Project) MarshalBytes() ([]byte, error) { w := &bytes.Buffer{} w.WriteString(xml.Header) diff --git a/pkg/util/maven/maven_repositories.go b/pkg/util/maven/maven_repositories.go index de0b8821f..441253c62 100644 --- a/pkg/util/maven/maven_repositories.go +++ b/pkg/util/maven/maven_repositories.go @@ -28,7 +28,6 @@ var DefaultRepositories = defaultRepositories{} type defaultRepositories struct{} -// nolint: unparam func (o defaultRepositories) apply(settings *Settings) error { for _, repository := range defaultMavenRepositories() { upsertRepository(repository, &settings.Profiles[0].Repositories) @@ -38,9 +37,9 @@ func (o defaultRepositories) apply(settings *Settings) error { } func defaultMavenRepositories() []v1.Repository { - defaultRepositories := strings.Split(DefaultMavenRepositories, ",") - repositories := make([]v1.Repository, 0, len(defaultRepositories)) - for _, repository := range defaultRepositories { + repos := strings.Split(DefaultMavenRepositories, ",") + repositories := make([]v1.Repository, 0, len(repos)) + for _, repository := range repos { repositories = append(repositories, NewRepository(repository)) } return repositories