Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<properties>
<java.version>21</java.version>
<maven.version>3.9.9</maven.version>
<slf4j.version>2.0.13</slf4j.version>
<slf4j.version>1.7.36</slf4j.version>
<junit-jupiter.version>5.12.2</junit-jupiter.version>
<site.path>snapshot</site.path>
<other.site.path>release</other.site.path>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,54 @@

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
* jenkins pipelines to avoid introducing new warnings.
*/
@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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompileProjectMojo> compile = new CompileMojoRule<>(
CompileProjectMojo.GOAL){
Expand Down Expand Up @@ -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]");
}

}
2 changes: 1 addition & 1 deletion src/test/resources/base/processes/myWebService.p.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"params" : [
{ "name" : "myText", "type" : "String", "desc" : "" }
],
"map" : { }
"code" : "//TEMPLATE!!"
}
},
"visual" : {
Expand Down
Loading