From 9a7c1d93aca5ec0190ca18c44a56c6515b15171a Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Wed, 21 May 2025 10:51:24 +0200 Subject: [PATCH 1/2] XIVY-16828 reproduce: warnings are propagated to Maven CLI console --- .../engine/Slf4jSimpleEngineProperties.java | 14 +++++ .../maven/TestSlf4jWarningConfiguration.java | 34 +++++++++++- .../maven/compile/TestCompileProjectMojo.java | 52 +++++++++++++++++++ .../base/processes/myWebService.p.json | 2 +- 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java b/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java index f80971a6..8db3a2e3 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java @@ -16,6 +16,7 @@ package ch.ivyteam.ivy.maven.engine; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; @@ -65,6 +66,19 @@ public static void install() { // only warnings from any logger used by ivy third parties (e.g. // org.apache.myfaces.xxx, org.apache.cxf, ...) System.setProperty(DEFAULT_LOG_LEVEL, Level.WARNING); + + // remain in same stream as the Maven CLI; don't use the default 'System.err' + System.setProperty(SimpleLogger.LOG_FILE_KEY, "System.out"); + } + + public static void enforceSimpleConfigReload() { + try { + Method initMethod = SimpleLogger.class.getDeclaredMethod("init"); + initMethod.setAccessible(true); + initMethod.invoke(null); + } catch (Exception ex) { + throw new RuntimeException(ex); + } } public static void reset() { diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java b/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java index 82c3745a..7ff3e2b4 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java +++ b/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java @@ -2,12 +2,24 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.slf4j.LoggerFactory; import org.slf4j.simple.SimpleLogger; import ch.ivyteam.ivy.maven.engine.Slf4jSimpleEngineProperties; class TestSlf4jWarningConfiguration { + + @BeforeEach + void setup() { + Slf4jSimpleEngineProperties.install(); + } + /* * XIVY-3123 Streamline the log output to be maven-like, instead of logging * [WARN] we want [WARNING]. This allows us to use the maven log parser on our @@ -15,9 +27,29 @@ class TestSlf4jWarningConfiguration { */ @Test void mavenLikeWarning() { - Slf4jSimpleEngineProperties.install(); assertThat(System.getProperty(SimpleLogger.WARN_LEVEL_STRING_KEY)) .as("SLF4J warning string is not maven-like [WARNING]") .isEqualTo("WARNING"); } + + @Test + void mavenLoggerWarningOut() throws IOException { + var original = System.out; + try (var bos = new ByteArrayOutputStream(); + var memoryOut = new PrintStream(bos);) { + System.setOut(memoryOut); + + var logger = LoggerFactory.getLogger("maven.cli"); + logger.warn("hey"); + + String out = bos.toString(); + assertThat(out) + .as("WARNING bracket matches Maven CLI") + .startsWith("[WARNING] hey"); + + } finally { + System.setOut(original); + } + } + } diff --git a/src/test/java/ch/ivyteam/ivy/maven/compile/TestCompileProjectMojo.java b/src/test/java/ch/ivyteam/ivy/maven/compile/TestCompileProjectMojo.java index 45440f2a..490e1d51 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/compile/TestCompileProjectMojo.java +++ b/src/test/java/ch/ivyteam/ivy/maven/compile/TestCompileProjectMojo.java @@ -18,21 +18,41 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.junit.After; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import ch.ivyteam.ivy.maven.BaseEngineProjectMojoTest; +import ch.ivyteam.ivy.maven.engine.Slf4jSimpleEngineProperties; import ch.ivyteam.ivy.maven.log.LogCollector; import ch.ivyteam.ivy.maven.util.PathUtils; public class TestCompileProjectMojo extends BaseEngineProjectMojoTest { private CompileTestProjectMojo testMojo; + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + + @Before + public void setup() { + Slf4jSimpleEngineProperties.enforceSimpleConfigReload(); + System.setOut(new PrintStream(outContent)); + } + + @After + public void restoreStreams() { + System.setOut(originalOut); + } + @Rule public CompileMojoRule compile = new CompileMojoRule<>( CompileProjectMojo.GOAL){ @@ -101,4 +121,36 @@ public void compilerSettingsFile_notFoundWarnings() throws Exception { mojo.execute(); assertThat(log.getWarnings().toString()).contains("Could not locate compiler settings file"); } + + @Test + public void validateProcess() throws Exception { + CompileProjectMojo mojo = compile.getMojo(); + + Path project = mojo.project.getBasedir().toPath(); + var dataClassDir = project.resolve("src_dataClasses"); + var wsProcDir = project.resolve("src_wsproc"); + PathUtils.clean(wsProcDir); + PathUtils.clean(dataClassDir); + + var ws = project.resolve("processes").resolve("myWebService.p.json"); + String wsJson = Files.readString(ws); + var patched = StringUtils.replace(wsJson, "//TEMPLATE!!", "ivy.session.assignRole(null);"); + Files.writeString(ws, patched); + + mojo.buildApplicationDirectory = Files.createTempDirectory("MyBuildApplicationVald"); + mojo.execute(); + + assertThat(outContent.toString()) + .contains("processes/myWebService.p.json /element=148CA74B16C580BF-ws0 : " + + "Start code: Method assignRole of class ch.ivyteam.ivy.workflow.IWorkflowSession " + + "is deprecated"); + + var warning = outContent.toString().lines() + .filter(l -> l.contains("/element=148CA74B16C580BF-ws0")) + .findFirst().get(); + assertThat(warning) + .as("WARNING prefix is streamlined with Maven CLI") + .startsWith("[WARNING]"); + } + } diff --git a/src/test/resources/base/processes/myWebService.p.json b/src/test/resources/base/processes/myWebService.p.json index ad0cc1b9..675f7747 100644 --- a/src/test/resources/base/processes/myWebService.p.json +++ b/src/test/resources/base/processes/myWebService.p.json @@ -16,7 +16,7 @@ "params" : [ { "name" : "myText", "type" : "String", "desc" : "" } ], - "map" : { } + "code" : "//TEMPLATE!!" } }, "visual" : { From 43f39c86c77ea7f22a59385ad8e99d88cc67e0f5 Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Fri, 23 May 2025 09:44:23 +0200 Subject: [PATCH 2/2] XIVY-16826 downgrade SFL4J to version 1.7.36 to comply with Maven 3.9 --- pom.xml | 2 +- .../ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java | 4 ++-- .../ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7e9ffb51..22315bd8 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 21 3.9.9 - 2.0.13 + 1.7.36 5.12.2 snapshot release diff --git a/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java b/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java index 8db3a2e3..1a5dbd10 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java @@ -20,7 +20,7 @@ import java.util.Arrays; import java.util.List; -import org.slf4j.simple.SimpleLogger; +import org.slf4j.impl.SimpleLogger; /** * Sets the logging properties for the ivy engine. @@ -105,7 +105,7 @@ private static void setDefaultProperty(String property, String value) { } /** - * Valid levels as documented in {@link org.slf4j.simple.SimpleLogger} + * Valid levels as documented in {@link SimpleLogger} */ interface Level { String TRACE = "trace"; diff --git a/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java b/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java index 7ff3e2b4..7c8fba5a 100644 --- a/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java +++ b/src/test/java/ch/ivyteam/ivy/maven/TestSlf4jWarningConfiguration.java @@ -9,7 +9,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; -import org.slf4j.simple.SimpleLogger; +import org.slf4j.impl.SimpleLogger; import ch.ivyteam.ivy.maven.engine.Slf4jSimpleEngineProperties;