diff --git a/pom.xml b/pom.xml index f752c09d..19685fab 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 f80971a6..1a5dbd10 100644 --- a/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java +++ b/src/main/java/ch/ivyteam/ivy/maven/engine/Slf4jSimpleEngineProperties.java @@ -16,10 +16,11 @@ package ch.ivyteam.ivy.maven.engine; +import java.lang.reflect.Method; 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. @@ -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() { @@ -91,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 82c3745a..7c8fba5a 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.simple.SimpleLogger; +import org.slf4j.LoggerFactory; +import org.slf4j.impl.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..9fcf0ba7 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.task.createNote(ivy.session, null).getWritterName();"); + 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 getWritterName of class ch.ivyteam.ivy.workflow.INote " + + "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 abc96797..ad32cece 100644 --- a/src/test/resources/base/processes/myWebService.p.json +++ b/src/test/resources/base/processes/myWebService.p.json @@ -1,5 +1,5 @@ { - "format" : "9.4.21", + "$schema" : "https://json-schema.axonivy.com/process/12.0.0/process.json", "id" : "148CA74B16C580BF", "kind" : "WEB_SERVICE", "config" : { @@ -11,18 +11,22 @@ "type" : "WebserviceStart", "name" : "call(String)", "config" : { - "callSignature" : "call", + "signature" : "call", "input" : { "params" : [ - { "name" : "myText", "type" : "String" } - ] + { "name" : "myText", "type" : "String", "desc" : "" } + ], + "map" : { }, + "code" : "//TEMPLATE!!" } }, "visual" : { "at" : { "x" : 96, "y" : 64 }, "labelOffset" : { "x" : 13, "y" : 37 } }, - "connect" : { "id" : "f0", "to" : "ws1" } + "connect" : [ + { "id" : "f0", "to" : "ws1" } + ] }, { "id" : "ws1", "type" : "WebserviceEnd",