You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2021/05/19 09:52:13 UTC

[camel-k] branch main updated: Check if the environment can produce structured Maven logs before parsing them

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 5b8f06d  Check if the environment can produce structured Maven logs before parsing them
5b8f06d is described below

commit 5b8f06d831ee8b1b0c4d779e6b8175665331d2c8
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Tue May 18 16:45:15 2021 +0200

    Check if the environment can produce structured Maven logs before parsing them
---
 pkg/util/maven/maven.go     | 10 ++++++----
 pkg/util/maven/maven_log.go | 14 +++++++++-----
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/pkg/util/maven/maven.go b/pkg/util/maven/maven.go
index 3979799..596627f 100644
--- a/pkg/util/maven/maven.go
+++ b/pkg/util/maven/maven.go
@@ -183,11 +183,13 @@ func Run(ctx Context) error {
 
 		mavenLog, parseError := ParseLog(line)
 
-		if parseError != nil {
-			// Do not abort the build because parsing failed ... the build may have succeeded
-			Log.Error(parseError, "Unable to parse maven log")
-		} else {
+		if parseError == nil {
 			NormalizeLog(mavenLog)
+		} 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,
+			// etc). The build may still have succeeded, though.
+			NonNormalizedLog(line)
 		}
 	}
 	Log.Debug("Finished parsing Maven output")
diff --git a/pkg/util/maven/maven_log.go b/pkg/util/maven/maven_log.go
index 57647e4..3b25368 100644
--- a/pkg/util/maven/maven_log.go
+++ b/pkg/util/maven/maven_log.go
@@ -43,6 +43,8 @@ const (
 	FATAL = "FATAL"
 )
 
+var mavenLogger = log.WithName("maven.build")
+
 func ParseLog(line string) (mavenLog MavenLog, error error) {
 	error = json.Unmarshal([]byte(line), &mavenLog)
 
@@ -50,14 +52,16 @@ func ParseLog(line string) (mavenLog MavenLog, error error) {
 }
 
 func NormalizeLog(mavenLog MavenLog) {
-	logger := log.WithName("maven.build")
-
 	switch mavenLog.Level {
 	case DEBUG, TRACE:
-		logger.Debug(mavenLog.Msg)
+		mavenLogger.Debug(mavenLog.Msg)
 	case INFO, WARN:
-		logger.Info(mavenLog.Msg)
+		mavenLogger.Info(mavenLog.Msg)
 	case ERROR, FATAL:
-		logger.Errorf(nil, mavenLog.Msg)
+		mavenLogger.Errorf(nil, mavenLog.Msg)
 	}
 }
+
+func NonNormalizedLog(rawLog string) {
+	mavenLogger.Info(rawLog)
+}